import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/utils/component/component.dart';
import 'package:search_people/value/topcolors.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class MenuAllPage extends GetView<MenuAllController> {
  const MenuAllPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return ListView(
      children: state.items
          .asMap()
          .map(
            (key, value) => MapEntry(
              key,
              MenuItemsWidget(
                md: value,
              ),
            ),
          )
          .values
          .toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MenuAllController>(
      builder: (_) {
        var state = controller.state;
        return Scaffold(
          appBar: detailAppBar(context, title: '全部服务', actions: [
            TextButton(
              onPressed: () {
                state.isEditing = !state.isEditing;
                controller.actionEdit();
              },
              child: Text(
                state.isEditing ? '完成' : '管理',
                style: TextStyle(
                    color: state.isEditing
                        ? TopColors.main_color
                        : TopColors.black_33,
                    fontSize: 16.sp),
              ),
            ),
          ]),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
